<?php
defined('IN_TS') or die('Access Denied.');

$arrUser = $new['user']->getOneUser($TS_USER['userid']);
if(!$arrUser['groupids']){
    tsNotice('你还没有在微澜社区报名，不能申报证章，请收藏本页，报名后再回到这个页面申报证章！',  '点击报名',tsUrl('user','welcome'));
}

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

$sort = $_GET['sort'];
$status = intval($_GET['status']);
$groupid = intval($_GET['groupid']);
$apply = intval($_GET['apply']);

$groupUser = aac('group')->findAll('group_user',array('userid'=>$TS_USER['userid'],'isvo'=>1),'addtime desc');
foreach($groupUser as $v){
    $arrGroup = aac('group')->find('group',array('groupid'=>$v['groupid']));
    if($arrGroup['isplace']==2&&$v['groupid']<>1){
        $groupname=$arrGroup['groupname'];
        $mygroupid = $v['groupid'];
        break;
    }
}


if($groupid){
    $arrData = 'groupid='.$groupid;
    $group = aac('group')->getOneGroup($groupid);
}else{
    $arrData = 'userid>0';
}

if($status == ''){
    $arrData = $arrData." and (status = 0 or status =2)";
    $title = '未处理的';
}
if($status == 1){
    $arrData = $arrData." and status = 1";
    $title = '已处理的';
}

if($title == ''){
    $title = '全部';
}
$title = $group['groupname'].$title;

$strGroup = aac('group')->findAll('group','isplace>0');

$lstart = $page*30-30;

$url = SITE_URL.'index.php?app=user&ac=apply&groupid='.$groupid.'&status='.$status.'&page=';

$arrApply	= $new['user']->findAll('user_apply',$arrData,'addtime desc','',$lstart.',30');

foreach($arrApply as $k=>$item){
    $arrApply[$k]['user'] = $new['user']->getOneUser($item['userid']);
    switch($item['type']){
        case 1:
            $arrApply[$k]['typename'] = '证书('.$item['score'].')';
            break;
        case 2:
            $arrApply[$k]['typename'] = '志士勋章';
            break;
        case 3:
            $arrApply[$k]['typename'] = '仁人勋章';
            break;
        case 4:
            $arrApply[$k]['typename'] = '贤者勋章';
            break;
        case 5:
            $arrApply[$k]['typename'] = '元勋勋章';
            break;
    }
}

$myApply = $new['user']->findAll('user_apply',array('userid'=>$TS_USER['userid']));
foreach($myApply as $v){
    $myApplyType[]=$v['type'];
}

$ApplyNum = $new['user']->findCount('user_apply',$arrData);

$pageUrl = pagination($ApplyNum, 30, $page, $url);

$title = $title.'申报';

include template("apply");
